package util

import (
	"encoding/base64"
	// "fmt"

	qrcode "github.com/skip2/go-qrcode"

	"errors"
	"os"
)

func GetQrcodeBase64(qrcode_str string) string {
	ret_str := ``
	err := qrcode.WriteFile(qrcode_str, qrcode.Medium, 90, "qrimage.png")
	if err == nil {
		//读原图片
		ff, _ := os.Open("qrimage.png")
		defer ff.Close()
		sourcebuffer := make([]byte, 10240)
		n, _ := ff.Read(sourcebuffer)
		//base64压缩
		sourcestring := base64.StdEncoding.EncodeToString(sourcebuffer[:n])

		ret_str = `data:image/png;base64,` + sourcestring

	} else {
		panic(errors.New("二维码写错误！"))
	}

	return ret_str
}
